app.controller("brandController",function($scope,$controller,brandService){
    $scope.list=[];
    $scope.brand ={};
    $scope.searchEntity={};
    $controller("baseController",{$scope:$scope});

    $scope.dele=function () {
        brandService.dele($scope.selectedIds).then(function(result){
            if(result.data.success){
                $scope.reloadList();
            }else{
                alert(result.data.message);
            }
        });
    }

    $scope.edit=function(id){
        brandService.findOne(id).then(function (result) {
            $scope.brand = result.data;
        })
    }
    $scope.save=function(){
        if($scope.brand.id){
            //编辑方法
            brandService.update($scope.brand).then(function(result){
                if(result.data.success){
                    $scope.reloadList();
                }else{
                    alert(result.data.message);
                }
            });
        }else {
            brandService.save($scope.brand).then(function(result){

                if(result.data.success){
                    $scope.reloadList();
                }else{
                    alert(result.data.message);
                }
            });
        }
    }

    $scope.findAll=function(){
        //去后台查数据
        brandService.findAll().then(function(result){
            $scope.list=result.data;
        });
    }


    $scope.search = function(page,rows){
        // 当前第几页    每页多少条
        brandService.findPage(page,rows,$scope.searchEntity).then(function(result){
            $scope.list = result.data.rows;
            $scope.pageModel.totalItems = result.data.total;
        });
    }


});